import {
	ref,
	watch
} from 'vue';
export const useAdd = ({
	num1,
	num2
}) => {
	const addNum = ref(0)
	watch([num1, num2], ([num1, num2]) => {
		addFn(num1, num2)
	})
	const addFn = (num1, num2) => {
		addNum.value = num1 + num2
	}
	return {
		addNum,
		addFn
	}
}

export function useFetch(url) {
	const data = ref(null)
	const error = ref(null)

	fetch(url)
		.then((res) => res.json())
		.then((json) => (data.value = json))
		.catch((err) => (error.value = err))

	return {
		data,
		error
	}
}